$(function() {

    //begin列表信息
    $("#classRoom_datagrid").datagrid({
        url: "/classRoom/list",
        columns: [[
            {field: "xxx", checkbox: 'true'},
            {field: "id", title: "编号", width: 100,hidden:true},
            {field: "name", title: "教室名称", width: 100},
            {field: "addre", title: "教室地址", width: 100},
            {field: "number", title: "座位数", width: 100},
            {field: "state", title: "状态", width: 100,formatter:function (value,row,index) {
                if(value == 1){
                    return "<font color='green'>可用</font>";
                }else if(value == 0){
                    return "<font color='red'>停用</font>";
                }
            }}
        ]],
        fit: true,
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        striped: true,
        pageNumber:1,
        pageSize:3,
        pageList:[3,5,10,20],
        toolbar: "#classRoom_tb"
    });
    //end列表信息

    //begin添加/编辑对话框
    $("#classRoom_dialog").dialog({
        width: 500,
        height: 500,
        buttons: "#classRoom_bb",
        closed: true
    });
    //end添加/编辑对话框

    //begin处理功能方法的对象
    var obj = {
        //begin添加按钮
        add: function () {
            $("#classRoom_form").form("clear");
            $("#classRoom_dialog").dialog("setTitle", "帅哥添加");
            $("#classRoom_dialog").dialog("open");
        },
        //end添加按钮

        //begin编辑按钮
        edit: function () {
            $("#classRoom_form").form("clear");
            $("#classRoom_dialog").dialog("setTitle", "帅哥编辑");
            var row = $("#classRoom_datagrid").datagrid("getSelected");
            if (!row) {
                $.messager.alert('温馨提示', '请选择要操作的行!');
                return;
            }
            $("#classRoom_form").form("load", row);
            $("#classRoom_dialog").dialog("open");
        },
        //end编辑按钮

        //begin取消按钮
        cancel: function () {
            $("#classRoom_dialog").dialog("close");
        },
        //end取消按钮

        //begin保存按钮
        save: function () {
            var classRoomId = $("#classRoomId").val();
            var url;
            if (classRoomId) {
                url = "/classRoom/update"
            } else {
                url = "/classRoom/save"
            }
            $("#classRoom_form").form("submit", {
                url: url,
                success: function (data) {
                    var data = $.parseJSON(data);
                    if (!data.success) {
                        $.messager.alert('温馨提示', data.msg);
                    } else {
                        $.messager.alert('温馨提示', "操作成功!");
                        $("#classRoom_dialog").dialog("close");
                        $("#classRoom_datagrid").datagrid("reload");
                    }
                }
            });
        },
        //end保存按钮

        //begin状态按钮
        remove:function(){
            var row = $("#classRoom_datagrid").datagrid("getSelected");
            if (!row) {
                $.messager.alert('温馨提示', '请选择要操作的行!');
                return;
            }
            $.messager.confirm('确认','您确认要操作此行吗？',function(r){
                if (r){
                    //注意这里的id要从当前选中的行中获取
                    var classRoomId = row.id;
                    $.get("/classRoom/changeState",{classRoomId:classRoomId},function(data){
                        if(!data.success){
                            $.messager.alert('温馨提示', data.msg);
                        }else{
                            $.messager.alert('温馨提示', '操作成功!');
                            $("#classRoom_datagrid").datagrid("reload");
                        }
                    });
                }
            });

        },
        //end状态按钮

        //begin刷新按钮
        reload:function (){
            $("#classRoom_datagrid").datagrid("reload")
        },
        //end刷新按钮

        //begin高级查询按钮
        queryKeyWord:function (){
            var keyword=$("#keyword").textbox("getValue");
            $("#classRoom_datagrid").datagrid("load",{
                keyword:keyword,
            })
        }
        //end高级查询按钮


    };
    //end处理功能方法的对象

    //begin处理功能方法对象,实际调用方法
    $("a[data-cmd]").click(function(){
        var cmd = $(this).data("cmd");
        obj[cmd]();
    });
    //end处理功能方法对象,实际调用方法





});